<template>
    <div>
      <el-dialog
        title="简答题"
        :visible.sync="editVisible"
        width="50%"
        :show-close="false"
        :close-on-click-modal="false">
        <el-form :model="editFormData" status-icon  ref="editFormData" label-width="80px" class="demo-ruleForm">
            <el-row>
              <el-col :span="20">
                <el-form-item label="题目:" prop="fb_title">
                  <el-input type="textarea" v-model="editFormData.fb_title" auto-complete="off"></el-input>
                </el-form-item>
              </el-col>
            </el-row>

            <div v-for="(v,k) in editFormData.FillAnsList" :key="k">
              <el-row style="margin-left: 60px;">
                <el-col :span="12">
                  <el-form-item :label="v.label">
                    <el-input v-model="v.value"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
        </el-form>
        <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog" size="mini">取 消</el-button>
        <el-button type="primary" @click="submitData" size="mini">确 定</el-button>
      </span>
      </el-dialog>
    </div>
</template>
<script>
  import {updateFill} from '@/api/questions'
  export default{
      props:["showEditVisible","rowData"],

      mounted(){
          this.editFormData = JSON.parse(JSON.stringify(this.rowData))
      },
      data(){
          return {
            editVisible:this.showEditVisible,
            editFormData:{}
          }
      },

      methods:{
        submitData(){
          this.$refs["editFormData"].validate((valid) =>{
            if(valid){
              let andStr = "";
              for(let i = 0;i < this.editFormData.FillAnsList.length;i ++){
                andStr += this.editFormData.FillAnsList[i].value;
                if(i < this.editFormData.FillAnsList.length - 1) {
                  andStr += "-"
                }
              }
              this.editFormData.fillBanksAnswer.fba_answer = andStr;
              updateFill(this.editFormData).then(res=>{
                if(res.code == 200){
                  this.$message({
                    type: 'success',
                    message: '修改成功'
                  });
                  this.closeDialog();
                }else{
                  this.$message({
                    type: 'error',
                    message: '修改失败'
                  });
                }
              })
            }
          });
        },

        closeDialog(){
            this.editVisible = false;
            this.$emit("closeDialog","edit")
        },
      }
  }
</script>
